﻿using Autofac;
using AutofacContrib.CommonServiceLocator;
using Microsoft.Practices.ServiceLocation;
using ZenMoney.Core.Container.Modules;

namespace ZenMoney.Core.Container
{
	public class Container
	{
		private static IServiceLocator _instance;

		public static IServiceLocator Instance
		{
			get 
			{
				if (_instance == null)
				{
					var container = BootstrapContainer();
					_instance = new AutofacServiceLocator(container);
				}

				return _instance;				
			}
		}

		private static IContainer BootstrapContainer()
		{
			var builder = new ContainerBuilder();

			builder.RegisterModule<InterceptionModule>();
			builder.RegisterModule<NHibernateModule>();
			builder.RegisterModule<ServiceModule>();
			
			return builder.Build();
		}
	}
}
